//
// Created by zhoubigbo on 2017/12/18.
//

#ifndef FFMPEGTEST_PLAYER_H
#define FFMPEGTEST_PLAYER_H


#define OPEN_INPUT_ERR 101
#define FIND_STREAM_ERR 102
#define FIND_CODEC_ERR 103
#define OPEN_CODEC_ERR 104


#include "audio.h"
#include "video.h"
#include "BlockingQueue.h"
extern "C"{
#include "libavformat/avformat.h"
};

class Player {

public:

    Player(Audio *audio,Video *video);

    virtual ~Player();

    AVFormatContext *fmtCtx;

    int init(const char *input);

    Audio *audio;
    Video *video;

    AVPacket *packet;
    BlockingQueue<AVPacket> *video_queue;
    BlockingQueue<AVPacket> *audio_queue;

    int ret;

    int audio_stream_index;
    int video_stream_index;

    int open_codec();
    void prepare_player();
    int prepare_video();
    int prepare_audio();

    void decode_frame(void (*fp)(int),void (*fpv)());

    void decode_video_frame(void (*fp)());
    void decode_audio_frame(void (*fp)(int));
    bool isPlaying;

};


#endif //FFMPEGTEST_PLAYER_H
